|
2 | 2 |
|
3 | 3 | from django.conf import settings
|
4 | 4 | from django.contrib.sites.models import Site
|
| 5 | +from django.core.mail import EmailMultiAlternatives |
5 | 6 | from django.utils.functional import lazy
|
6 | 7 | from django.utils import translation
|
7 | 8 | from django.utils.translation import get_language
|
8 | 9 |
|
9 |
| -from kitsune.sumo.email_utils import emails_with_users_and_watches, safe_translation |
| 10 | +from kitsune.sumo.email_utils import emails_with_users_and_watches, safe_translation, send_messages |
10 | 11 | from kitsune.sumo.tests import TestCase
|
11 | 12 | from kitsune.users.tests import UserFactory
|
12 | 13 |
|
@@ -132,3 +133,26 @@ def test_styles_inlining(self):
|
132 | 133 | for m in msg:
|
133 | 134 | tag = '<a href="https://%s/test" style="color:#000">Hyperlink</a>'
|
134 | 135 | self.assertIn(tag % Site.objects.get_current().domain, str(m.message()))
|
| 136 | + |
| 137 | + |
| 138 | +class SendMessagesTests(TestCase): |
| 139 | + |
| 140 | + @patch("kitsune.sumo.email_utils.mail") |
| 141 | + def test_send_messages(self, mock_mail): |
| 142 | + from_email = "notifications@support.mozilla.org" |
| 143 | + messages = [ |
| 144 | + EmailMultiAlternatives("Test", "Testing", from_email, ["beatles"]), |
| 145 | + EmailMultiAlternatives( |
| 146 | + "Test", "Testing", from_email, ["george.harrison.@gmail.com", "ringo"] |
| 147 | + ), |
| 148 | + EmailMultiAlternatives("Test", "Testing", from_email, ["paul.mccartney.@gmail.com"]), |
| 149 | + EmailMultiAlternatives( |
| 150 | + "Test", "Testing", from_email, ["ringo@beatles.com", "george@beatles.com"] |
| 151 | + ), |
| 152 | + ] |
| 153 | + send_messages(messages) |
| 154 | + send_messages_mock = mock_mail.get_connection().__enter__().send_messages |
| 155 | + send_messages_mock.assert_called_once_with([messages[1], messages[2], messages[3]]) |
| 156 | + self.assertEqual(messages[1].to, ["georgeharrison@gmail.com"]) |
| 157 | + self.assertEqual(messages[2].to, ["paulmccartney@gmail.com"]) |
| 158 | + self.assertEqual(messages[3].to, ["ringo@beatles.com", "george@beatles.com"]) |
0 commit comments